<?php 

	
	if(!isset($_SESSION['username'])){
		echo "<script>alert('请登录！');window.location.href='index.php?m=admin&c=manage'</script>";die;
	}
	
	//dbselect($con,$table,$field='*',$where='',$order='',$limit='')
	$auth = dbselect($con,'authonity','*','id<>1');


	//添加权限角色时的权限多选框无极分类
	$authc = child($auth);

	assign('authc',$authc);

	if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])=='xmlhttprequest'){
		if(isset($_POST['auth'])){
			$auth = htmlspecialchars( trim($_POST['auth'] ,"") );

			$resultp = dbselect($con,'permission','per_name',"per_name='{$auth}'");

			if($resultp){
				echo 1;die;
			}else{
				echo 0;die;
			}
			
		}else if(isset($_POST['checks'])){

			$check = $_POST['checks'];

			$per_name = htmlspecialchars(trim($_POST['per_na'],""));


			//dbinsert($con,$table,$field)
			$filed['per_name'] = $per_name;
			$filed['auth_id'] = $check;
			$per_insert = dbinsert($con,'permission',$filed);

			if($per_insert){
				echo 1;die;
			}else{
				echo 0;die;
			}

		}else if(isset($_POST['caut_id'])){
			$caut_id = $_POST['caut_id'];

			$query = dbselect($con,'authonity','id',"pid='{$caut_id}'");

			echo json_encode($query);die;
		}

	}
	
	

	//权限管理
	authonity($con);

?>